home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / edit / thesrc20.zip / execute.c < prev    next >
C/C++ Source or Header  |  1995-01-26  |  90KB  |  2,379 lines

  1. /***********************************************************************/
  2. /* EXECUTE.C -                                                         */
  3. /* This file contains all functions that actually execute one or other */
  4. /* commands.                                                           */
  5. /***********************************************************************/
  6. /*
  7.  * THE - The Hessling Editor. A text editor similar to VM/CMS xedit.
  8.  * Copyright (C) 1991-1995 Mark Hessling
  9.  *
  10.  * This program is free software; you can redistribute it and/or
  11.  * modify it under the terms of the GNU General Public License as
  12.  * published by the Free Software Foundation; either version 2 of
  13.  * the License, or any later version.
  14.  *
  15.  * This program is distributed in the hope that it will be useful,
  16.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18.  * General Public License for more details.
  19.  *
  20.  * You should have received a copy of the GNU General Public License
  21.  * along with this program; if not, write to:
  22.  *
  23.  *    The Free Software Foundation, Inc.
  24.  *    675 Mass Ave,
  25.  *    Cambridge, MA 02139 USA.
  26.  *
  27.  *
  28.  * If you make modifications to this software that you feel increases
  29.  * it usefulness for the rest of the community, please email the
  30.  * changes, enhancements, bug fixes as well as any and all ideas to me.
  31.  * This software is going to be maintained and enhanced as deemed
  32.  * necessary by the community.
  33.  *
  34.  * Mark Hessling                     email: M.Hessling@gu.edu.au
  35.  * 36 David Road                     Phone: +61 7 849 7731
  36.  * Holland Park                      Fax:   +61 7 875 5314
  37.  * QLD 4121
  38.  * Australia
  39.  */
  40.  
  41. /*
  42. $Id: execute.c 2.0 1995/01/26 16:30:58 MH Release MH $
  43. */
  44.  
  45. #include <stdio.h>
  46.  
  47. #include "the.h"
  48. #include "proto.h"
  49.  
  50. /***********************************************************************/
  51. #ifdef PROTO
  52. short execute_change_command(CHARTYPE *params,bool selective)
  53. #else
  54. short execute_change_command(params,selective)
  55. CHARTYPE *params;
  56. bool selective;
  57. #endif
  58. /***********************************************************************/
  59. {
  60. /*-------------------------- external data ----------------------------*/
  61.  extern CHARTYPE *rec;
  62.  extern unsigned short rec_len;
  63. /*--------------------------- local data ------------------------------*/
  64.  LINETYPE num_lines=0L,long_n=0L,long_m=0L;
  65.  LINE *curr=NULL;
  66.  CHARTYPE *old_str=NULL,*new_str=NULL;
  67.  short rc=0,selective_rc=RC_OK;
  68.  short  direction=DIRECTION_FORWARD;
  69.  short number_lines=0,number_changes=0,number_of_changes=0,number_of_occ=0;
  70.  short start_col=0,real_start=0,real_end=0,loc=0;
  71.  LINETYPE true_line=0L,last_true_line=0L,final_target=0L;
  72.  LINETYPE num_actual_lines=0L,abs_num_lines=0L,i=0L;
  73.  short len_old_str=0,len_new_str=0;
  74.  TARGET target;
  75.  CHARTYPE message[40];
  76.  bool lines_based_on_scope=FALSE;
  77. /*--------------------------- processing ------------------------------*/
  78. #ifdef TRACE
  79.  trace_function("commutil.c:execute_change_command");
  80. #endif
  81. /*---------------------------------------------------------------------*/
  82. /* Validate the parameters that have been supplied. Up to 4 parameters */
  83. /* may be supplied. The first is the string to change and its new      */
  84. /* value, the second is the target, the third is the number of times   */
  85. /* to change the value on one line and lastly is which occurrence to   */
  86. /* change first.                                                       */
  87. /*---------------------------------------------------------------------*/
  88.  initialise_target(&target);
  89.  rc = split_change_params(params,&old_str,&new_str,&target,&long_n,&long_m);
  90.  if (rc != RC_OK)
  91.    {
  92.     free_target(&target);
  93. #ifdef TRACE
  94.     trace_return();
  95. #endif
  96.     return(rc);
  97.    }
  98.  num_lines = target.num_lines;
  99.  true_line = target.true_line;
  100.  if (target.rt == NULL)
  101.     lines_based_on_scope = TRUE;
  102.  else
  103.     lines_based_on_scope = (target.rt[0].target_type == TARGET_BLOCK_CURRENT) ? FALSE : TRUE;
  104.  free_target(&target);
  105. /*---------------------------------------------------------------------*/
  106. /* Check for any hex strings in both old_str and new_str.              */
  107. /*---------------------------------------------------------------------*/
  108.  if (CURRENT_VIEW->hex)
  109.    {
  110.     if ((len_old_str = convert_hex_strings(old_str)) == (-1))
  111.       {
  112.        display_error(32,(CHARTYPE *)"",FALSE);
  113. #ifdef TRACE
  114.        trace_return();
  115. #endif
  116.        return(RC_INVALID_OPERAND);
  117.       }
  118.     if ((len_new_str = convert_hex_strings(new_str)) == (-1))
  119.       {
  120.        display_error(32,(CHARTYPE *)"",FALSE);
  121. #ifdef TRACE
  122.        trace_return();
  123. #endif
  124.        return(RC_INVALID_OPERAND);
  125.       }
  126.    }
  127.  else
  128.    {
  129.     len_old_str = strlen(old_str);
  130.     len_new_str = strlen(new_str);
  131.    }
  132. /*---------------------------------------------------------------------*/
  133. /* If the number of lines is zero, don't make any  changes. Exit with  */
  134. /* no rows changed.                                                    */
  135. /*---------------------------------------------------------------------*/
  136.  if (num_lines == 0L)
  137.    {
  138.     display_error(36,(CHARTYPE *)"",FALSE);
  139. #ifdef TRACE
  140.     trace_return();
  141. #endif
  142.     return(RC_NO_LINES_CHANGED);
  143.    }
  144.  if (num_lines < 0)
  145.    {
  146.     direction = DIRECTION_BACKWARD;
  147.     abs_num_lines = -num_lines;
  148.    }
  149.  else
  150.    {
  151.     direction = DIRECTION_FORWARD;
  152.     abs_num_lines = num_lines;
  153.    }
  154.  
  155.  final_target = true_line+num_lines;
  156.  
  157.  if (true_line != CURRENT_VIEW->focus_line)
  158.    {
  159.     post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line);
  160.     pre_process_line(CURRENT_VIEW,true_line);
  161.    }
  162.  number_lines = 0;
  163.  number_changes = 0;
  164.  number_of_changes = 0;
  165.  number_of_occ = 0;
  166.  start_col = 0;
  167.  last_true_line = true_line;
  168.  curr = lll_find(CURRENT_FILE->first_line,true_line);
  169.  for (i=0L,num_actual_lines=0L;;i++)
  170.    {
  171.     if (lines_based_on_scope)
  172.       {
  173.        if (num_actual_lines == abs_num_lines)
  174.           break;
  175.       }
  176.     else
  177.       {
  178.        if (abs_num_lines == i)
  179.           break;
  180.       }
  181.     rc = processable_line(CURRENT_VIEW,true_line,curr);
  182.     switch(rc)
  183.       {
  184.        case LINE_SHADOW:
  185.             break;
  186.        case LINE_TOF_EOF:
  187.             num_actual_lines++;
  188.             break;
  189.        default:
  190.             loc = 0;
  191.             number_of_changes = number_of_occ = 0;
  192.             while(loc != (-1))
  193.               {
  194.                real_end = min(rec_len+len_old_str,CURRENT_VIEW->zone_end-1);
  195.                real_start = max(start_col,CURRENT_VIEW->zone_start-1);
  196.  
  197.                if (rec_len < real_start && blank_field(old_str))
  198.                  {
  199.                   loc = 0;
  200.                   rec_len = real_start+1;
  201.                  }
  202.                else
  203.                  {
  204.                   loc = memfind(rec+real_start,old_str,(real_end-real_start+1),
  205.                                 len_old_str,
  206.                                 (CURRENT_VIEW->case_change == CASE_IGNORE) ? TRUE : FALSE,
  207.                                 CURRENT_VIEW->arbchar_status,
  208.                                 CURRENT_VIEW->arbchar_single,
  209.                                 CURRENT_VIEW->arbchar_multiple);
  210.                  }
  211.                if (loc != (-1))
  212.                  {
  213.                   start_col = loc+real_start;
  214.                   if (number_of_changes <= long_n-1 && number_of_occ >= long_m-1)
  215.                     {
  216.                     /* the following block is done for change or confirm of sch */
  217.                      if (!selective)
  218.                        {
  219.                         memdelchr(rec,start_col,rec_len,len_old_str);
  220.                         rec_len = max(start_col,rec_len - len_old_str);
  221.                         meminsmem(rec,new_str,len_new_str,start_col,max_line_length,rec_len);
  222.                         rec_len += len_new_str;
  223.                         if (rec_len > max_line_length)
  224.                           {
  225.                            rec_len = max_line_length;
  226.                            loc = (-1);
  227.                           }
  228.                         start_col += len_new_str;
  229.                         number_changes++;
  230.                         number_of_changes++;
  231.                        }
  232.                      else
  233.                        {
  234.                        /* selective */
  235.                         selective_rc = selective_change(old_str,len_old_str,new_str,len_new_str,
  236.                                                         true_line,last_true_line,start_col);
  237.                         last_true_line = true_line;
  238.                         switch(selective_rc)
  239.                           {
  240.                            case QUITOK:
  241.                            case RC_OK:
  242.                                 start_col += len_new_str;
  243.                                 number_changes++;
  244.                                 number_of_changes++;
  245.                                 if (rec_len > max_line_length)
  246.                                   {
  247.                                    rec_len = max_line_length;
  248.                                    loc = (-1);
  249.                                   }
  250.                                 break;
  251.                            case SKIP:
  252.                                 start_col += len_old_str;
  253.                                 break;
  254.                            case QUIT:
  255.                                 break;
  256.                           }
  257.                         if (selective_rc == QUIT || selective_rc == QUITOK)
  258.                            break;
  259.                        }
  260.                      number_of_occ++;
  261.                     }
  262.                   else
  263.                     {
  264.                      start_col += len_old_str;
  265.                      number_of_occ++;
  266.                     }
  267.                   if (number_of_changes > long_n-1)
  268.         /*          ||  number_of_occ > long_n-1)*/
  269.                      loc = (-1);
  270.                  }
  271.               } /* end while */
  272.             if (number_of_changes != 0)       /* changes made */
  273.               {
  274.                post_process_line(CURRENT_VIEW,true_line);
  275.                number_lines++;
  276.               }
  277.             num_actual_lines++;
  278.             break;
  279.       }
  280.     if (selective_rc == QUIT || selective_rc == QUITOK)
  281.        break;
  282.     start_col = 0;
  283.     if (direction == DIRECTION_FORWARD)
  284.        curr = curr->next;
  285.     else
  286.        curr = curr->prev;
  287.     true_line += (LINETYPE)(direction);
  288.     pre_process_line(CURRENT_VIEW,true_line);
  289.    }
  290. /*---------------------------------------------------------------------*/
  291. /* If no changes were made, display error message and return.          */
  292. /*---------------------------------------------------------------------*/
  293.  if (number_changes == 0)
  294.    {
  295.     display_error(36,(CHARTYPE *)"",FALSE);
  296.     pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line);
  297. #ifdef TRACE
  298.     trace_return();
  299. #endif
  300.     return(RC_NO_LINES_CHANGED);
  301.    }
  302. /*---------------------------------------------------------------------*/
  303. /* If STAY is OFF, change the current and focus lines by the number    */
  304. /* of lines calculated from the target.                                */
  305. /*---------------------------------------------------------------------*/
  306.  if (!CURRENT_VIEW->stay)                                /* stay is off */
  307.     CURRENT_VIEW->focus_line = CURRENT_VIEW->current_line = final_target;
  308.  
  309.  pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line);
  310.  build_current_screen();
  311.  display_current_screen();
  312.  
  313.  sprintf(message,"%d occurrence(s) changed on %d line(s)",number_changes,number_lines);
  314.  display_error(0,message,TRUE);
  315. #ifdef TRACE
  316.  trace_return();
  317. #endif
  318.  if (CURRENT_TOF || CURRENT_BOF)
  319.     return(RC_TOF_EOF_REACHED);
  320.  else
  321.     return(RC_OK);
  322. }
  323. /***********************************************************************/
  324. #ifdef PROTO
  325. short selective_change(CHARTYPE *old_str,short len_old_str,CHARTYPE *new_str,
  326.                        short len_new_str,LINETYPE true_line,LINETYPE last_true_line,short start_col)
  327. #else
  328. short selective_change(old_str,len_old_str,new_str,len_new_str,true_line,last_true_line,start_col)
  329. CHARTYPE *old_str;
  330. short len_old_str;
  331. CHARTYPE *new_str;
  332. short len_new_str;
  333. LINETYPE true_line;
  334. LINETYPE last_true_line;
  335. short start_col;
  336. #endif
  337. /***********************************************************************/
  338. {
  339. /*-------------------------- external data ----------------------------*/
  340.  extern unsigned short rec_len;
  341.  extern CHARTYPE *rec;
  342. /*--------------------------- local data ------------------------------*/
  343.  register short i=0;
  344.  short y=0,x=0,rc=RC_OK;
  345.  int key=0;
  346.  bool changed=FALSE;
  347.  bool line_displayed=FALSE;
  348. /*--------------------------- processing ------------------------------*/
  349. #ifdef TRACE
  350.  trace_function("commutil.c:selective_change");
  351. #endif
  352.  
  353.  getyx(CURRENT_WINDOW_MAIN,y,x);
  354.                 /* move cursor to old string a la cmatch */
  355.                 /* display message */
  356.                 /* accept key - C next, - N change, - Q to quit */
  357.  
  358.  CURRENT_VIEW->focus_line = true_line;
  359. /*---------------------------------------------------------------------*/
  360. /* Check if the true_line is in the currently displayed window.        */
  361. /* If not, then change the current_line to the true_line.              */
  362. /*---------------------------------------------------------------------*/
  363.  line_displayed = FALSE;
  364.  for (i=0;i<CURRENT_SCREEN.rows[WINDOW_MAIN];i++)
  365.    {
  366.     if (CURRENT_SCREEN.sl[i].line_number == true_line
  367.     &&  CURRENT_SCREEN.sl[i].line_type == LINE_LINE)
  368.       {
  369.        line_displayed = TRUE;
  370.        y = i;
  371.        break;
  372.       }
  373.    }
  374.  if (!line_displayed)
  375.    {
  376.     CURRENT_VIEW->current_line = CURRENT_VIEW->focus_line;
  377.     y = CURRENT_VIEW->current_row;
  378.    }
  379.  
  380.  if (start_col >= CURRENT_VIEW->verify_col-1
  381.  &&  start_col <= (CURRENT_SCREEN.cols[WINDOW_MAIN]+(CURRENT_VIEW->verify_col-1))-1)
  382.     x = start_col-(CURRENT_VIEW->verify_col-1);
  383.  else
  384.    {
  385.     x = CURRENT_SCREEN.cols[WINDOW_MAIN] / 2;
  386.     CURRENT_VIEW->verify_col = max(1,start_col-(short)x);
  387.     x = (start_col-(CURRENT_VIEW->verify_col-1));
  388.    }
  389.  
  390.  key = 0;
  391.  changed = FALSE;
  392.  while(key == 0)
  393.    {
  394.     build_current_screen();
  395.     display_current_screen();
  396.     if (changed)
  397.        display_prompt("Press 'N' for next,'C' to undo 'Q' to quit");
  398.     else
  399.        display_prompt("Press 'N' for next,'C' to change 'Q' to quit");
  400.     wmove(CURRENT_WINDOW_MAIN,y,x);
  401.     wrefresh(CURRENT_WINDOW_MAIN);
  402.  
  403.     key = my_getch(stdscr);
  404.     clear_msgline();
  405.     switch(key)
  406.       {
  407.        case 'N':
  408.        case 'n':
  409.             if (changed)
  410.                rc = RC_OK;
  411.             else
  412.                rc = SKIP;
  413.             break;
  414.        case 'C':
  415.        case 'c':
  416.             if (changed)
  417.               {
  418.                memdelchr(rec,start_col,rec_len,len_new_str);
  419.                rec_len -= len_new_str;
  420.                meminsmem(rec,old_str,len_old_str,start_col,max_line_length,rec_len);
  421.                rec_len += len_old_str;
  422.               }
  423.             else
  424.               {
  425.                memdelchr(rec,start_col,rec_len,len_old_str);
  426.                rec_len -= len_old_str;
  427.                meminsmem(rec,new_str,len_new_str,start_col,max_line_length,rec_len);
  428.                rec_len += len_new_str;
  429.               }
  430.             changed = (changed) ? FALSE : TRUE;
  431.             key = 0;
  432.             break;
  433.        case 'Q':
  434.        case 'q':
  435.             if (changed)
  436.                rc = QUITOK;
  437.             else
  438.                rc = QUIT;
  439.             break;
  440.        default:
  441.             key = 0;
  442.             break;
  443.       }
  444.    }
  445. #ifdef TRACE
  446.  trace_return();
  447. #endif
  448.  return(rc);
  449. }
  450. /***********************************************************************/
  451. #ifdef PROTO
  452. short insert_new_line(CHARTYPE *line,short len,LINETYPE num_lines,LINETYPE true_line,bool start_left_col,bool make_current,CHARTYPE select)
  453. #else
  454. short insert_new_line(line,len,num_lines,true_line,start_left_col,make_current,select)
  455. CHARTYPE *line;
  456. short len;
  457. LINETYPE num_lines;
  458. LINETYPE true_line;
  459. bool start_left_col;
  460. bool make_current;
  461. CHARTYPE select;
  462. #endif
  463. /***********************************************************************/
  464. {
  465. /*-------------------------- external data ----------------------------*/
  466.  extern bool in_profile;
  467. /*--------------------------- local data ------------------------------*/
  468.  register short i=0;
  469.  LINE *curr=NULL,*save_curr=NULL;
  470.  unsigned short x=0,y=0;
  471.  short rc=RC_OK,new_col=0;
  472.  bool on_bottom_of_file=FALSE,on_bottom_of_screen=FALSE;
  473.  short number_focus_rows=0;
  474.  bool leave_cursor=FALSE;
  475.  LINETYPE new_focus_line=0L,new_current_line=0L;
  476. /*--------------------------- processing ------------------------------*/
  477. #ifdef TRACE
  478.  trace_function("commutil.c:insert_new_line");
  479. #endif
  480.  if (!CURRENT_VIEW->scope_all)
  481.     true_line = find_last_not_in_scope(NULL,true_line,DIRECTION_FORWARD);
  482. /*---------------------------------------------------------------------*/
  483. /* If we are on the 'Bottom of File' line reduce the true_line by 1    */
  484. /* so that the new line is added before the bottom line.               */
  485. /*---------------------------------------------------------------------*/
  486.  if (true_line == CURRENT_FILE->number_lines+1L)
  487.     true_line--;
  488. /*---------------------------------------------------------------------*/
  489. /* Find the current LINE pointer for the true_line.                    */
  490. /* This is the line after which the line(s) are to be added.           */
  491. /*---------------------------------------------------------------------*/
  492.  curr = lll_find(CURRENT_FILE->first_line,true_line);
  493. /*---------------------------------------------------------------------*/
  494. /* Insert into the linked list the number of lines specified. All lines*/
  495. /* will contain a blank line and a length of zero.                     */
  496. /*---------------------------------------------------------------------*/
  497.  save_curr = curr;
  498.  for (i=0;i<num_lines;i++)
  499.     {
  500.      if ((curr = add_line(CURRENT_FILE->first_line,curr,line,len,select)) == NULL)
  501.        {
  502.         display_error(30,(CHARTYPE *)"",FALSE);
  503. #ifdef TRACE
  504.         trace_return();
  505. #endif
  506.         return(RC_OUT_OF_MEMORY);
  507.        }
  508.     }
  509. /*---------------------------------------------------------------------*/
  510. /* Fix the positioning of the marked block (if there is one and it is  */
  511. /* in the current view) and any pending prefix commands.               */
  512. /*---------------------------------------------------------------------*/
  513.  adjust_marked_lines(TRUE,true_line,num_lines);
  514.  adjust_pending_prefix(CURRENT_VIEW,TRUE,true_line,num_lines);
  515. /*---------------------------------------------------------------------*/
  516. /* Increment the number of lines counter for the current file and the  */
  517. /* number of alterations.                                              */
  518. /*---------------------------------------------------------------------*/
  519.  if ((rc = increment_alt(CURRENT_FILE)) != RC_OK)
  520.    {
  521. #ifdef TRACE
  522.     trace_return();
  523. #endif
  524.     return(rc);
  525.    }
  526.  CURRENT_FILE->number_lines += num_lines;
  527. /*---------------------------------------------------------------------*/
  528. /* Sort out focus and current line.                                    */
  529. /*---------------------------------------------------------------------*/
  530.  switch(CURRENT_VIEW->current_window)
  531.    {
  532.     case WINDOW_COMMAND:
  533.          CURRENT_VIEW->focus_line = true_line + 1L;
  534.          if (make_current)
  535.             CURRENT_VIEW->current_line = true_line + 1L;
  536.          pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line);
  537.          break;
  538.     case WINDOW_MAIN:
  539.     case WINDOW_PREFIX:
  540.          build_current_screen();
  541.          getyx(CURRENT_WINDOW,y,x);
  542.          calculate_scroll_values(&number_focus_rows,&new_focus_line,
  543.                                  &new_current_line,
  544.                                  &on_bottom_of_screen,&on_bottom_of_file,
  545.                                  &leave_cursor,DIRECTION_FORWARD);
  546.          new_col = x;
  547.          if (CURRENT_VIEW->current_window == WINDOW_MAIN)
  548.            {
  549.             if (!start_left_col)
  550.               {
  551.                if (CURRENT_VIEW->newline_aligned)
  552.                  {
  553.                   new_col = memne(save_curr->line,' ',save_curr->length);
  554.                   if (new_col == (-1))
  555.                      new_col = 0;
  556. /*---------------------------------------------------------------------*/
  557. /* Special case when right margin is > than screen width...            */
  558. /*---------------------------------------------------------------------*/
  559.                   if (CURRENT_VIEW->verify_start != CURRENT_VIEW->verify_col)
  560.                     {
  561. /*---------------------------------------------------------------------*/
  562. /* If the new column position will be on the same page...              */
  563. /*---------------------------------------------------------------------*/
  564.                      if (CURRENT_VIEW->verify_col < new_col
  565.                      &&  CURRENT_VIEW->verify_col + CURRENT_SCREEN.screen_cols > new_col)
  566.                         new_col = (new_col - CURRENT_VIEW->verify_col) + 1;
  567.                      else
  568.                        {
  569.                         x = CURRENT_SCREEN.cols[WINDOW_MAIN] / 2;
  570.                         CURRENT_VIEW->verify_col = max(1,new_col - (short)x + 2);
  571.                         new_col = (CURRENT_VIEW->verify_col == 1) ? new_col : x - 1;
  572.                        }
  573.                     }
  574.                  }
  575.                else
  576.                  {
  577.                   new_col = 0;
  578.                   CURRENT_VIEW->verify_col = 1;
  579.                  }
  580.               }
  581.            }
  582. /*---------------------------------------------------------------------*/
  583. /* Move the cursor to where it should be and display the page.         */
  584. /*---------------------------------------------------------------------*/
  585.          if (on_bottom_of_screen)
  586.            {
  587.             CURRENT_VIEW->current_line = new_current_line;
  588.             CURRENT_VIEW->focus_line = new_focus_line;
  589.             wmove(CURRENT_WINDOW,y-((leave_cursor) ? 0 : 1),new_col);
  590.            }
  591.          else
  592.            {
  593. /*---------------------------------------------------------------------*/
  594. /* We are in the middle of the window, so just move the cursor down    */
  595. /* 1 line.                                                             */
  596. /*---------------------------------------------------------------------*/
  597.            wmove(CURRENT_WINDOW,y+number_focus_rows,new_col);
  598.            CURRENT_VIEW->focus_line = new_focus_line;
  599.           }
  600.          break;
  601.    }
  602.  pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line);
  603.  build_current_screen();
  604.  display_current_screen();
  605.  
  606. #ifdef TRACE
  607.  trace_return();
  608. #endif
  609.  return(RC_OK);
  610. }
  611. /***********************************************************************/
  612. #ifdef PROTO
  613. short execute_os_command(CHARTYPE *cmd,bool quiet,bool pause)
  614. #else
  615. short execute_os_command(cmd,quiet,pause)
  616. CHARTYPE *cmd;
  617. bool quiet;
  618. bool pause;
  619. #endif
  620. /***********************************************************************/
  621. {
  622. /*-------------------------- external data ----------------------------*/
  623.  extern CHARTYPE *temp_cmd;
  624.  extern bool curses_started;
  625. /*--------------------------- local data ------------------------------*/
  626. #if defined(DOS) || defined(OS2)
  627. #define SHELL "COMSPEC"
  628. #else
  629. #define SHELL "SHELL"
  630. #endif
  631. /*--------------------------- processing ------------------------------*/
  632. #ifdef TRACE
  633.  trace_function("commutil.c:execute_os_command");
  634. #endif
  635.  
  636. #ifdef MSWIN
  637.  quiet = 1;
  638.  pause = 0;
  639. #endif
  640.  
  641.  if (!quiet && curses_started)
  642.    {
  643.     attrset(A_NORMAL);
  644.     touchwin(stdscr);
  645.     wmove(stdscr,0,0);
  646.     addch(' ');
  647.     wmove(stdscr,1,0);
  648.     wrefresh(stdscr);   /* clear screen */
  649.     suspend_curses();
  650.    }
  651.  if (allocate_temp_space(strlen(cmd),TEMP_TEMP_CMD) != RC_OK)
  652.     {
  653.      display_error(30,(CHARTYPE *)"",FALSE);
  654. #ifdef TRACE
  655.      trace_return();
  656. #endif
  657.      return(RC_OUT_OF_MEMORY);
  658.     }
  659.  if (strcmp(cmd,"") == 0)
  660.     strcpy(temp_cmd,getenv(SHELL));
  661.  else
  662.     strcpy(temp_cmd,cmd);
  663. #ifdef UNIX
  664.  if (strcmp(temp_cmd,"") == 0)           /* no SHELL env variable set */
  665.    {
  666.     printf("No SHELL environment variable set - using /bin/sh\n");
  667.     fflush(stdout);
  668.     strcpy(temp_cmd,"/bin/sh");
  669.    }
  670. #endif
  671.  if (quiet)
  672.    {
  673. #ifdef UNIX
  674.     strcat(temp_cmd," > /dev/null");
  675. #endif
  676. #if defined(DOS) || defined(OS2)
  677.     strcat(temp_cmd," > nul:");
  678. #endif
  679.    }
  680.  system(temp_cmd);
  681.  if (pause)
  682.    {
  683.     printf("\n\n%s",HIT_ANY_KEY);
  684.     fflush(stdout);
  685.    }
  686.  if (!quiet && curses_started)
  687.    {
  688.     resume_curses();
  689.     if (pause)
  690.        (void)my_getch(stdscr);
  691.     restore_THE();
  692.    }
  693.  if (curses_started)
  694.     draw_cursor(TRUE);
  695. #ifdef TRACE
  696.  trace_return();
  697. #endif
  698.  return(RC_OK);
  699. }
  700. /***********************************************************************/
  701. #ifdef PROTO
  702. short execute_makecurr(LINETYPE line)
  703. #else
  704. short execute_makecurr(line)
  705. LINETYPE line;
  706. #endif
  707. /***********************************************************************/
  708. {
  709. /*-------------------------- external data ----------------------------*/
  710. /*--------------------------- local data ------------------------------*/
  711.  unsigned short y=0,x=0;
  712. /*--------------------------- processing ------------------------------*/
  713. #ifdef TRACE
  714.  trace_function("commutil.c:execute_makecurr");
  715. #endif
  716.  post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line);
  717.  
  718.  CURRENT_VIEW->current_line = line;
  719.  if (CURRENT_VIEW->current_window == WINDOW_PREFIX)
  720.     getyx(CURRENT_WINDOW,y,x);
  721.  else
  722.     getyx(CURRENT_WINDOW_MAIN,y,x);
  723.  build_current_screen();
  724.  display_current_screen();
  725.  y = get_row_for_focus_line(CURRENT_VIEW->focus_line,
  726.                             CURRENT_VIEW->current_row);
  727.  if (CURRENT_VIEW->current_window == WINDOW_PREFIX)
  728.     wmove(CURRENT_WINDOW,y,x);
  729.  else
  730.     wmove(CURRENT_WINDOW_MAIN,y,x);
  731. #ifdef TRACE
  732.  trace_return();
  733. #endif
  734.  return(RC_OK);
  735. }
  736. /***********************************************************************/
  737. #ifdef PROTO
  738. short execute_shift_command(short shift_left,short num_cols,LINETYPE true_line,LINETYPE num_lines,bool lines_based_on_scope)
  739. #else
  740. short execute_shift_command(shift_left,num_cols,true_line,num_lines,lines_based_on_scope)
  741. short shift_left,num_cols;
  742. LINETYPE true_line,num_lines;
  743. bool lines_based_on_scope;
  744. #endif
  745. /***********************************************************************/
  746. {
  747. /*-------------------------- external data ----------------------------*/
  748.  extern bool curses_started;
  749. /*-------------------------- external data ----------------------------*/
  750.  extern unsigned short rec_len;
  751.  extern CHARTYPE *rec;
  752. /*--------------------------- local data ------------------------------*/
  753.  unsigned short y=0,x=0;
  754.  LINE *curr=NULL;
  755.  LINETYPE abs_num_lines=(num_lines < 0L ? -num_lines : num_lines);
  756.  LINETYPE i=0L;
  757.  LINETYPE num_actual_lines=0L;
  758.  register short j=0;
  759.  short actual_cols=0;
  760.  short rc=RC_OK;
  761.  short direction=(num_lines < 0L ? DIRECTION_BACKWARD : DIRECTION_FORWARD);
  762. /*--------------------------- processing ------------------------------*/
  763. #ifdef TRACE
  764.  trace_function("commutil.c:execute_shift_command");
  765. #endif
  766.  post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line);
  767.  if (CURRENT_VIEW->current_window == WINDOW_COMMAND)
  768.     getyx(CURRENT_WINDOW_MAIN,y,x);
  769.  else
  770.     getyx(CURRENT_WINDOW,y,x);
  771.  curr = lll_find(CURRENT_FILE->first_line,true_line);
  772. /* for (i=0L;i<abs_num_lines;i++)*/
  773. /*   {*/
  774.  for (i=0L,num_actual_lines=0L;;i++)
  775.    {
  776.     if (lines_based_on_scope)
  777.       {
  778.        if (num_actual_lines == abs_num_lines)
  779.           break;
  780.       }
  781.     else
  782.       {
  783.        if (abs_num_lines == i)
  784.           break;
  785.       }
  786.     rc = processable_line(CURRENT_VIEW,true_line+(LINETYPE)(i*direction),curr);
  787.     switch(rc)
  788.       {
  789.        case LINE_SHADOW:
  790.             break;
  791.        case LINE_TOF_EOF:
  792.             num_actual_lines++;
  793.             break;
  794.        default:
  795.             memset(rec,' ',max_line_length);
  796.             memcpy(rec,curr->line,curr->length);
  797.             rec_len = curr->length;
  798.             if (shift_left)
  799.               {
  800.                actual_cols = min(num_cols,max(0,rec_len-(CURRENT_VIEW->zone_start-1)));
  801.                memdelchr(rec,CURRENT_VIEW->zone_start-1,rec_len,actual_cols);
  802.                rec_len -= actual_cols;
  803.               }
  804.             else
  805.               {
  806.                for (j=0;j<num_cols;j++)
  807.                   meminschr(rec,' ',CURRENT_VIEW->zone_start-1,max_line_length,rec_len++);
  808.                rec_len = min(rec_len,max_line_length);
  809.                actual_cols = num_cols;
  810.               }
  811. /*---------------------------------------------------------------------*/
  812. /* Increment the alteration counters only if line has changed.         */
  813. /*---------------------------------------------------------------------*/
  814.             if (actual_cols != 0)
  815.               {
  816.                if ((rc = increment_alt(CURRENT_FILE)) != RC_OK)
  817.                  {
  818. #ifdef TRACE
  819.                   trace_return();
  820. #endif
  821.                   return(rc);
  822.                  }
  823. /*---------------------------------------------------------------------*/
  824. /* Add the old line contents to the line recovery list.                */
  825. /*---------------------------------------------------------------------*/
  826.                add_to_recovery_list(curr->line,curr->length);
  827. /*---------------------------------------------------------------------*/
  828. /* Realloc the dynamic memory for the line if the line is now longer.  */
  829. /*---------------------------------------------------------------------*/
  830.                if (rec_len > curr->length)
  831.                               /* what if realloc fails ?? */
  832.                   curr->line = (CHARTYPE *)(*the_realloc)((void *)curr->line,(rec_len+1)*sizeof(CHARTYPE));
  833. /*---------------------------------------------------------------------*/
  834. /* Copy the contents of rec into the line.                             */
  835. /*---------------------------------------------------------------------*/
  836.                memcpy(curr->line,rec,rec_len);
  837.                curr->length = rec_len;
  838.                *(curr->line+rec_len) = '\0';
  839.               }
  840.             num_actual_lines++;
  841.             break;
  842.       }
  843. /*---------------------------------------------------------------------*/
  844. /* Proceed to the next record, even if the current record not in scope.*/
  845. /*---------------------------------------------------------------------*/
  846.     if (direction == DIRECTION_BACKWARD)
  847.        curr = curr->prev;
  848.     else
  849.        curr = curr->next;
  850.    }
  851. /*---------------------------------------------------------------------*/
  852. /* If STAY is OFF, change the current and focus lines by the number    */
  853. /* of lines calculated from the target.                                */
  854. /*---------------------------------------------------------------------*/
  855.  if (!CURRENT_VIEW->stay                                 /* stay is off */
  856.  &&  num_lines != 0L)
  857.     CURRENT_VIEW->focus_line = CURRENT_VIEW->current_line = true_line+num_lines-(LINETYPE)direction;
  858.  pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line);
  859.  build_current_screen();
  860.  display_current_screen();
  861.  if (CURRENT_VIEW->current_window != WINDOW_COMMAND
  862.  &&  curses_started)
  863.    {
  864.     getyx(CURRENT_WINDOW,y,x);
  865.     y = get_row_for_focus_line(CURRENT_VIEW->focus_line,
  866.                                CURRENT_VIEW->current_row);
  867.     wmove(CURRENT_WINDOW,y,x);
  868.    }
  869. #ifdef TRACE
  870.  trace_return();
  871. #endif
  872.  return(RC_OK);
  873. }
  874. /***********************************************************************/
  875. #ifdef PROTO
  876. short execute_change_case(CHARTYPE *params,CHARTYPE which_case)
  877. #else
  878. short execute_change_case(params,which_case)
  879. CHARTYPE *params;
  880. CHARTYPE which_case;
  881. #endif
  882. /***********************************************************************/
  883. {
  884. /*-------------------------- external data ----------------------------*/
  885.  extern bool curses_started;
  886.  extern VIEW_DETAILS *vd_mark;
  887. /*--------------------------- local data ------------------------------*/
  888.  register short i=0;
  889.  LINETYPE num_lines=0L,true_line=0L,num_actual_lines=0L;
  890.  unsigned short x=0,y=0;
  891.  short  direction=0;
  892.  LINE *curr=NULL;
  893.  short start_col=0,end_col=0;
  894.  short rc=RC_OK;
  895.  TARGET target;
  896.  short target_type=TARGET_NORMAL|TARGET_BLOCK_CURRENT|TARGET_ALL;
  897.  bool lines_based_on_scope=TRUE;
  898. /*--------------------------- processing ------------------------------*/
  899. #ifdef TRACE
  900.  trace_function("commutil.c:execute_change_case");
  901. #endif
  902. /*---------------------------------------------------------------------*/
  903. /* Validate the parameters that have been supplied.                    */
  904. /* Valid values are: a target or "block".                              */
  905. /* If no parameter is supplied, 1 is assumed.                          */
  906. /*---------------------------------------------------------------------*/
  907.  if (strcmp("",params) == 0)
  908.     params = (CHARTYPE *)"1";
  909.  initialise_target(&target);
  910.  if ((rc = validate_target(params,&target,target_type,get_true_line(),TRUE,TRUE)) != RC_OK)
  911.    {
  912.     free_target(&target);
  913. #ifdef TRACE
  914.     trace_return();
  915. #endif
  916.     return(rc);
  917.    }
  918.  post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line);
  919. /*---------------------------------------------------------------------*/
  920. /* Determine in which direction we are working.                        */
  921. /*---------------------------------------------------------------------*/
  922.  if (target.num_lines < 0L)
  923.    {
  924.     direction = DIRECTION_BACKWARD;
  925.     num_lines = target.num_lines * (-1L);
  926.    }
  927.  else
  928.    {
  929.     direction = DIRECTION_FORWARD;
  930.     num_lines = target.num_lines;
  931.    }
  932.  true_line = target.true_line;
  933. /*---------------------------------------------------------------------*/
  934. /* If the target is BLOCK set the left and right margins to be the     */
  935. /* margins of the BOX BLOCK, otherwise use ZONE settings.              */
  936. /*---------------------------------------------------------------------*/
  937.  start_col = CURRENT_VIEW->zone_start-1;
  938.  end_col = CURRENT_VIEW->zone_end-1;
  939.  if (target.rt[0].target_type == TARGET_BLOCK_CURRENT)
  940.    {
  941.     num_lines = MARK_VIEW->mark_end_line-MARK_VIEW->mark_start_line+1L;
  942.     true_line = MARK_VIEW->mark_start_line;
  943.     direction = DIRECTION_FORWARD;
  944.     lines_based_on_scope = FALSE;
  945.     if (MARK_VIEW->mark_type != M_LINE)
  946.       {
  947.        start_col = MARK_VIEW->mark_start_col-1;
  948.        end_col   = MARK_VIEW->mark_end_col-1;
  949.       }
  950.    }
  951. /*---------------------------------------------------------------------*/
  952. /* Find the current LINE pointer for the true_line.                    */
  953. /* This is the first line to change.                                   */
  954. /*---------------------------------------------------------------------*/
  955.  curr = lll_find(CURRENT_FILE->first_line,true_line);
  956. /*---------------------------------------------------------------------*/
  957. /* Change the case for the target lines and columns...                 */
  958. /*---------------------------------------------------------------------*/
  959.  for (i=0L,num_actual_lines=0L;;i++)
  960.    {
  961.     if (lines_based_on_scope)
  962.       {
  963.        if (num_actual_lines == num_lines)
  964.           break;
  965.       }
  966.     else
  967.       {
  968.        if (num_lines == i)
  969.           break;
  970.       }
  971.     rc = processable_line(CURRENT_VIEW,true_line+(LINETYPE)(i*direction),curr);
  972.     switch(rc)
  973.       {
  974.        case LINE_SHADOW:
  975.             break;
  976.        case LINE_TOF_EOF:
  977.             num_actual_lines++;
  978.             break;
  979.        default:
  980.             add_to_recovery_list(curr->line,curr->length);
  981.             change_case(curr->line,max(0,start_col),min(curr->length-1,end_col),which_case);
  982.             num_actual_lines++;
  983.             break;
  984.        }
  985.      if (direction == DIRECTION_FORWARD)
  986.         curr = curr->next;
  987.      else
  988.         curr = curr->prev;
  989.     }
  990.  if (!CURRENT_VIEW->stay                                 /* stay is off */
  991.  &&  target.num_lines != 0L)
  992.     CURRENT_VIEW->focus_line = CURRENT_VIEW->current_line = target.true_line+target.num_lines-(LINETYPE)direction;
  993.  free_target(&target);
  994.  pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line);
  995.  build_current_screen();
  996.  display_current_screen();
  997.  if (CURRENT_VIEW->current_window != WINDOW_COMMAND
  998.  &&  curses_started)
  999.    {
  1000.     getyx(CURRENT_WINDOW,y,x);
  1001.     y = get_row_for_focus_line(CURRENT_VIEW->focus_line,
  1002.                                CURRENT_VIEW->current_row);
  1003.     wmove(CURRENT_WINDOW,y,x);
  1004.    }
  1005. #ifdef TRACE
  1006.  trace_return();
  1007. #endif
  1008.  if (CURRENT_TOF || CURRENT_BOF)
  1009.     return(RC_TOF_EOF_REACHED);
  1010.  else
  1011.     return(RC_OK);
  1012. }
  1013. /***********************************************************************/
  1014. #ifdef PROTO
  1015. short change_case(CHARTYPE *str,short start,short end,CHARTYPE which_case)
  1016. #else
  1017. short change_case(str,start,end,which_case)
  1018. CHARTYPE *str;
  1019. short start,end;
  1020. CHARTYPE which_case;
  1021. #endif
  1022. /***********************************************************************/
  1023. {
  1024. /*-------------------------- external data ----------------------------*/
  1025. /*--------------------------- local data ------------------------------*/
  1026.  register short i=0;
  1027.  bool altered=FALSE;
  1028.  short rc=RC_OK;
  1029. /*--------------------------- processing ------------------------------*/
  1030. #ifdef TRACE
  1031.  trace_function("commutil.c:change_case");
  1032. #endif
  1033.  for (i=start;i<end+1;i++)
  1034.    {
  1035.     switch(which_case)
  1036.       {
  1037.        case CASE_UPPER:
  1038.                        if (islower(*(str+i)))
  1039.                          {
  1040.                           *(str+i) = toupper(*(str+i));
  1041.                           altered = TRUE;
  1042.                          }
  1043.                        break;
  1044.        case CASE_LOWER:
  1045.                        if (isupper(*(str+i)))
  1046.                          {
  1047.                           *(str+i) = tolower(*(str+i));
  1048.                           altered = TRUE;
  1049.                          }
  1050.                        break;
  1051.       }
  1052.    }
  1053. /*---------------------------------------------------------------------*/
  1054. /* Increment the number of alterations count if anything cahnged.      */
  1055. /*---------------------------------------------------------------------*/
  1056.  if (altered)
  1057.     if ((rc = increment_alt(CURRENT_FILE)) != RC_OK)
  1058.       {
  1059. #ifdef TRACE
  1060.        trace_return();
  1061. #endif
  1062.        return(rc);
  1063.       }
  1064.  
  1065. #ifdef TRACE
  1066.  trace_return();
  1067. #endif
  1068.  return(RC_OK);
  1069. }
  1070. /***********************************************************************/
  1071. #ifdef PROTO
  1072. short rearrange_line_blocks(CHARTYPE command,CHARTYPE source,
  1073.                           LINETYPE start_line,LINETYPE end_line,LINETYPE dest_line,short num_occ,
  1074.                           VIEW_DETAILS *src_view,VIEW_DETAILS *dst_view,bool lines_based_on_scope)
  1075. #else
  1076. short rearrange_line_blocks(command,source,start_line,end_line,dest_line,num_occ,src_view,dst_view,lines_based_on_scope)
  1077. CHARTYPE command,source;
  1078. LINETYPE start_line,end_line,dest_line;
  1079. short num_occ;
  1080. VIEW_DETAILS *src_view,*dst_view;
  1081. bool lines_based_on_scope;
  1082. #endif
  1083. /***********************************************************************/
  1084. /* Parameters:                                                         */
  1085. /*    command: the command being executed; COPY,DELETE,DUPLICATE,MOVE  */
  1086. /*     source: where the command is executed; COMMAND, PREFIX, BLOCK   */
  1087. /* start_line: the first line (or only line) number to be acted on     */
  1088. /*   end_line: the last line number to be acted on                     */
  1089. /*  dest_line: the destination line for copy,move and duplicate. For   */
  1090. /*             delete this is not applicable.                          */
  1091. /*    num_occ: the number of times to execute the command; only for DUP*/
  1092. /***********************************************************************/
  1093. {
  1094. /*-------------------------- external data ----------------------------*/
  1095.  extern bool in_profile;
  1096.  extern VIEW_DETAILS *vd_mark;
  1097. /*--------------------------- local data ------------------------------*/
  1098.  register short j=0,k=0;
  1099.  short rc=RC_OK;
  1100.  static unsigned short y=0,x=0;
  1101.  bool dst_inside_src=FALSE,lines_added=FALSE,reset_block=FALSE;
  1102.  bool dest_in_block=FALSE;
  1103.  short  direction=0;
  1104.  LINETYPE num_lines=0L,off=0L,adjust_line=dest_line,num_actual_lines=0L;
  1105.  LINETYPE i=0L,num_pseudo_lines=0L;
  1106.  LINE *curr_src=NULL,*curr_dst=NULL;
  1107.  LINE *save_curr_src=NULL,*save_curr_dst=NULL;
  1108.  FILE_DETAILS *src_file=NULL,*dst_file=NULL;
  1109. /*--------------------------- processing ------------------------------*/
  1110. #ifdef TRACE
  1111.  trace_function("commutil.c:rearrange_line_blocks");
  1112. #endif
  1113.  src_file = src_view->file_for_view;
  1114.  dst_file = dst_view->file_for_view;
  1115.  if (source == SOURCE_BLOCK)
  1116.     reset_block = FALSE;
  1117.  else
  1118.     reset_block = TRUE;
  1119. /*---------------------------------------------------------------------*/
  1120. /* This block of commands is for copying lines...                      */
  1121. /*---------------------------------------------------------------------*/
  1122.  switch(command)
  1123.    {
  1124.     case COMMAND_COPY:
  1125.     case COMMAND_MOVE_COPY_SAME:
  1126.     case COMMAND_MOVE_COPY_DIFF:
  1127.     case COMMAND_DUPLICATE:
  1128.          lines_added = TRUE;
  1129.          switch(source)
  1130.            {
  1131.             case SOURCE_BLOCK:
  1132.             case SOURCE_BLOCK_RESET:
  1133.                  if (src_view == dst_view
  1134.                  &&  dest_line >= start_line
  1135.                  &&  dest_line <  end_line)
  1136.                      dest_in_block = TRUE;
  1137.                  break;
  1138.             case SOURCE_PREFIX:
  1139.                  if (dest_line >= start_line
  1140.                  &&  dest_line <  end_line)
  1141.                      dest_in_block = TRUE;
  1142.                  break;
  1143.             default:
  1144.                  break;
  1145.            }
  1146. /*---------------------------------------------------------------------*/
  1147. /* If the destination line is within the marked block then we have to  */
  1148. /* handle the processing of the src_curr pointer differently.          */
  1149. /*---------------------------------------------------------------------*/
  1150.          if (dest_in_block)
  1151.            {
  1152.             dst_inside_src = TRUE;
  1153.             off = dest_line - start_line;
  1154.            }
  1155.          else
  1156.             dst_inside_src = FALSE;
  1157.          num_lines = end_line - start_line + 1L;
  1158.          save_curr_src = lll_find(src_file->first_line,start_line);
  1159.          save_curr_dst = lll_find(dst_file->first_line,dest_line);
  1160.          for (k=0;k<num_occ;k++)
  1161.            {
  1162.             curr_src = save_curr_src;
  1163.             curr_dst = save_curr_dst;
  1164.             for (i=0L,num_actual_lines=0L;;i++)
  1165.                {
  1166.                 if (lines_based_on_scope)
  1167.                   {
  1168.                    if (num_actual_lines == num_lines)
  1169.                       break;
  1170.                   }
  1171.                 else
  1172.                   {
  1173.                    if (num_lines == i)
  1174.                       break;
  1175.                   }
  1176.                 rc = processable_line(src_view,start_line+i,curr_src);
  1177.                 switch(rc)
  1178.                   {
  1179.                    case LINE_SHADOW:
  1180.                         break;
  1181.                    case LINE_TOF_EOF:
  1182.                         num_actual_lines++;
  1183.                         num_pseudo_lines++;
  1184.                         break;
  1185.                    default:
  1186.                         if ((curr_dst = add_line(dst_file->first_line,curr_dst,
  1187.                                         curr_src->line,curr_src->length,
  1188.                                         curr_src->select)) == NULL)
  1189.                           {
  1190.                            display_error(30,(CHARTYPE *)"",FALSE);
  1191. #ifdef TRACE
  1192.                            trace_return();
  1193. #endif
  1194.                            return(RC_OUT_OF_MEMORY);
  1195.                           }
  1196. /*---------------------------------------------------------------------*/
  1197. /* If moving lines within the same file, move any line name with the   */
  1198. /* line also.                                                          */
  1199. /*---------------------------------------------------------------------*/
  1200.                           if (command == COMMAND_MOVE_COPY_SAME)
  1201.                             {
  1202.                              if (curr_src->name != (CHARTYPE *)NULL)
  1203.                                {
  1204.                                 curr_dst->name = curr_src->name;
  1205.                                 curr_src->name = (CHARTYPE *)NULL;
  1206.                                }
  1207.                             }
  1208.                           num_actual_lines++;
  1209.                           break;
  1210.                   }
  1211.                    if (dst_inside_src && i == off)
  1212.                       for (j=0;j<off+1;j++)
  1213.                          curr_src = curr_src->next;
  1214.                    curr_src = curr_src->next;
  1215.               }
  1216.             }
  1217.          dst_file->number_lines += (num_actual_lines-num_pseudo_lines)*num_occ;
  1218.          break;
  1219.     default:
  1220.          break;
  1221.    }
  1222. /*---------------------------------------------------------------------*/
  1223. /* This block of commands is for deleting lines...                     */
  1224. /*---------------------------------------------------------------------*/
  1225.  switch(command)
  1226.    {
  1227.     case COMMAND_DELETE:
  1228.     case COMMAND_MOVE_DELETE_SAME:
  1229.     case COMMAND_MOVE_DELETE_DIFF:
  1230.          lines_added = FALSE;
  1231.          if (start_line > end_line)
  1232.            {
  1233.             direction = DIRECTION_BACKWARD;
  1234.             num_lines = start_line - end_line + 1L;
  1235.            }
  1236.          else
  1237.            {
  1238.             direction = DIRECTION_FORWARD;
  1239.             num_lines = end_line - start_line + 1L;
  1240.            }
  1241.          curr_dst = lll_find(dst_file->first_line,start_line);
  1242. /*         for (i=0,num_actual_lines=0;num_actual_lines<num_lines,curr_dst!=NULL;i++)*/
  1243. /*         for (i=0,num_actual_lines=0;i<num_lines;i++)*/
  1244.          for (i=0L,num_actual_lines=0L;;i++)
  1245.            {
  1246.             if (lines_based_on_scope)
  1247.               {
  1248.                if (num_actual_lines == num_lines)
  1249.                   break;
  1250.               }
  1251.             else
  1252.               {
  1253.                if (num_lines == i)
  1254.                   break;
  1255.               }
  1256.             rc = processable_line(dst_view,start_line+i,curr_dst);
  1257.             switch(rc)
  1258.               {
  1259.                case LINE_TOF_EOF:
  1260.                     num_actual_lines++; /* this is meant to fall through */
  1261.                     num_pseudo_lines++;
  1262.                case LINE_SHADOW:
  1263.                     if (direction == DIRECTION_FORWARD)
  1264.                        curr_dst = curr_dst->next;
  1265.                     else
  1266.                        curr_dst = curr_dst->prev;
  1267.                     break;
  1268.                default:
  1269.                     if (command != COMMAND_MOVE_DELETE_SAME)
  1270.                        add_to_recovery_list(curr_dst->line,curr_dst->length);
  1271.                     curr_dst = delete_line(dst_file->first_line,curr_dst,direction);
  1272.                     num_actual_lines++;
  1273.               }
  1274.             if (curr_dst == NULL)
  1275.                break;
  1276.            }
  1277.          dst_file->number_lines -= (num_actual_lines-num_pseudo_lines)*num_occ;
  1278.          break;
  1279.     default:
  1280.          break;
  1281.    }
  1282. /*---------------------------------------------------------------------*/
  1283. /* Increment alteration count for all but COMMAND_MOVE_COPY_SAME...    */
  1284. /*---------------------------------------------------------------------*/
  1285.  if (command != COMMAND_MOVE_COPY_SAME
  1286.  &&  (num_actual_lines-num_pseudo_lines) != 0)
  1287.    {
  1288.     if ((rc = increment_alt(dst_file)) != RC_OK)
  1289.       {
  1290. #ifdef TRACE
  1291.        trace_return();
  1292. #endif
  1293.        return(rc);
  1294.       }
  1295.    }
  1296. /*---------------------------------------------------------------------*/
  1297. /* This block of commands is for sorting out cursor position...        */
  1298. /*---------------------------------------------------------------------*/
  1299.  switch(command)
  1300.    {
  1301.     case COMMAND_COPY:
  1302.     case COMMAND_MOVE_COPY_SAME:
  1303.     case COMMAND_MOVE_COPY_DIFF:
  1304.     case COMMAND_DUPLICATE:
  1305.          if (source == SOURCE_COMMAND
  1306.          &&  CURRENT_VIEW->stay)
  1307.              break;
  1308.          if (IN_VIEW(dst_view,dest_line))
  1309.            {
  1310.             dst_view->focus_line = dest_line+1L;
  1311.            }
  1312.          if (dst_view->current_window != WINDOW_COMMAND
  1313.          &&  dst_view == CURRENT_SCREEN.screen_view)
  1314.            {
  1315.             getyx(CURRENT_WINDOW,y,x);
  1316.             if (y == CURRENT_SCREEN.rows[WINDOW_MAIN]-1)/* on bottom line of window */
  1317.               {
  1318.                dst_view->current_line = dst_view->focus_line;
  1319.                y = dst_view->current_row;
  1320.               }
  1321.             else
  1322.                y = get_row_for_focus_line(dst_view->focus_line,
  1323.                                           dst_view->current_row);
  1324.            }
  1325.          break;
  1326.     case COMMAND_DELETE:
  1327.     case COMMAND_MOVE_DELETE_SAME:
  1328.     case COMMAND_MOVE_DELETE_DIFF:
  1329.          if (dst_view->focus_line >= start_line
  1330.          &&  dst_view->focus_line <= end_line)
  1331.            {
  1332.             if (IN_VIEW(dst_view,dest_line))
  1333.               {
  1334.                if (dst_view->current_line > dst_file->number_lines+1L)
  1335.                   dst_view->current_line -= (num_actual_lines-num_pseudo_lines);
  1336.                dst_view->focus_line = dest_line;
  1337.               }
  1338.             else
  1339.               {
  1340.                if (dest_line > dst_file->number_lines)
  1341.                   dst_view->focus_line = dst_view->current_line = dst_file->number_lines;
  1342.                else
  1343.                   dst_view->focus_line = dst_view->current_line = dest_line;
  1344.               }
  1345.            }
  1346.          else
  1347.            {
  1348.             dest_line = (dst_view->focus_line < start_line ? dst_view->focus_line : dst_view->focus_line - num_lines);
  1349.             if (IN_VIEW(dst_view,dest_line))
  1350.               {
  1351.                if (dst_view->current_line > dst_file->number_lines+1L)
  1352.                   dst_view->current_line -= (num_actual_lines-num_pseudo_lines);
  1353.                dst_view->focus_line = dest_line;
  1354.               }
  1355.             else
  1356.               {
  1357.                if (dest_line > dst_file->number_lines)
  1358.                   dst_view->focus_line = dst_view->current_line = dst_file->number_lines;
  1359.                else
  1360.                   dst_view->focus_line = dst_view->current_line = dest_line;
  1361.               }
  1362.            }
  1363.          if (dst_file->number_lines == 0L)
  1364.                dst_view->focus_line = dst_view->current_line = 0L;
  1365.          if (dst_view->current_window != WINDOW_COMMAND
  1366.          &&  dst_view == CURRENT_SCREEN.screen_view)
  1367.            {
  1368.             getyx(CURRENT_WINDOW,y,x);
  1369.             y = get_row_for_focus_line(dst_view->focus_line,
  1370.                                        dst_view->current_row);
  1371.            }
  1372. /*---------------------------------------------------------------------*/
  1373. /* This is set here so that the adjust_pending_prefix command will work*/
  1374. /*---------------------------------------------------------------------*/
  1375.          if (direction == DIRECTION_BACKWARD)
  1376.             adjust_line = end_line;
  1377.          else
  1378.             adjust_line = start_line;
  1379.          dst_view->current_line = find_next_in_scope(NULL,dst_view->current_line,DIRECTION_FORWARD);
  1380.          break;
  1381.     default:
  1382.          break;
  1383.    }
  1384. /*---------------------------------------------------------------------*/
  1385. /* This block of commands is for adjusting prefix and block lines...   */
  1386. /*---------------------------------------------------------------------*/
  1387.  switch(source)
  1388.    {
  1389.     case SOURCE_BLOCK:
  1390.     case SOURCE_BLOCK_RESET:
  1391.          adjust_pending_prefix(dst_view,lines_added,adjust_line,(num_actual_lines-num_pseudo_lines)*num_occ);
  1392.          if (command == COMMAND_MOVE_DELETE_SAME)
  1393.             adjust_marked_lines(lines_added,adjust_line,(num_actual_lines-num_pseudo_lines)*num_occ);
  1394.          else
  1395.             if (command != COMMAND_MOVE_DELETE_DIFF)
  1396.               {
  1397.                MARK_VIEW->marked_line = MARK_VIEW->marked_col = FALSE;
  1398. /*---------------------------------------------------------------------*/
  1399. /* The following does a 'reset block' in the current view.             */
  1400. /*---------------------------------------------------------------------*/
  1401.                if (reset_block)
  1402.                  {
  1403.                   dst_view->marked_line = dst_view->marked_col = FALSE;
  1404.                   MARK_VIEW = (VIEW_DETAILS *)NULL;
  1405.                  }
  1406.                else
  1407.                  {
  1408.                   dst_view->mark_start_line = dest_line + 1L;
  1409.                   dst_view->mark_end_line = dest_line + (num_actual_lines-num_pseudo_lines);
  1410.                   dst_view->marked_col = FALSE;
  1411.                   dst_view->mark_type = M_LINE;
  1412.                   dst_view->focus_line = dst_view->mark_start_line;
  1413.                   MARK_VIEW = dst_view;
  1414.                  }
  1415.               }
  1416.          break;
  1417.     case SOURCE_PREFIX:
  1418.     case SOURCE_COMMAND:
  1419.          adjust_marked_lines(lines_added,adjust_line,(num_actual_lines-num_pseudo_lines)*num_occ);
  1420.          adjust_pending_prefix(dst_view,lines_added,adjust_line,(num_actual_lines-num_pseudo_lines)*num_occ);
  1421.          break;
  1422.    }
  1423.  if (command != COMMAND_MOVE_DELETE_DIFF)
  1424.     pre_process_line(CURRENT_VIEW,dst_view->focus_line);
  1425. /*---------------------------------------------------------------------*/
  1426. /* If run from the profile, exit here.                                 */
  1427. /*---------------------------------------------------------------------*/
  1428.  if (in_profile)
  1429.    {
  1430. #ifdef TRACE
  1431.     trace_return();
  1432. #endif
  1433.     return(RC_OK);
  1434.    }
  1435.  if (command != COMMAND_MOVE_DELETE_DIFF
  1436.  &&  command != COMMAND_MOVE_COPY_SAME)
  1437.    {
  1438.     build_current_screen();
  1439.     display_current_screen();
  1440.    }
  1441.  if (dst_view->current_window != WINDOW_COMMAND
  1442.  &&  dst_view == CURRENT_SCREEN.screen_view)
  1443.     wmove(CURRENT_WINDOW,y,x);
  1444. #ifdef TRACE
  1445.  trace_return();
  1446. #endif
  1447.  return(RC_OK);
  1448. }
  1449. /***********************************************************************/
  1450. #ifdef PROTO
  1451. short execute_set_point(CHARTYPE *name,LINETYPE true_line,bool point_on)
  1452. #else
  1453. short execute_set_point(name,true_line,point_on)
  1454. CHARTYPE *name;
  1455. LINETYPE true_line;
  1456. bool point_on;
  1457. #endif
  1458. /***********************************************************************/
  1459. /* Parameters:                                                         */
  1460. /*       name: the name of the line to be processed                    */
  1461. /*  true_line: the line number of the line                             */
  1462. /*   point_on: indicates if the line name is to be turned on or off    */
  1463. /***********************************************************************/
  1464. {
  1465. /*-------------------------- external data ----------------------------*/
  1466. /*--------------------------- local data ------------------------------*/
  1467.  LINE *curr=NULL;
  1468.  LINETYPE dummy=0L;
  1469. /*--------------------------- processing ------------------------------*/
  1470. #ifdef TRACE
  1471.  trace_function("commutil.c:execute_set_point");
  1472. #endif
  1473.  if (point_on)
  1474.    {
  1475. /*---------------------------------------------------------------------*/
  1476. /* Find a line that already has the same name. If one exists, remove   */
  1477. /* the name.                                                           */
  1478. /*---------------------------------------------------------------------*/
  1479.     if ((curr = find_named_line(name,&dummy,FALSE)) != (LINE *)NULL)
  1480.       {
  1481.        (*the_free)(curr->name);
  1482.        curr->name = (CHARTYPE *)NULL;
  1483.       }
  1484. /*---------------------------------------------------------------------*/
  1485. /* Allocate space for the name and attach it to the true_line.         */
  1486. /*---------------------------------------------------------------------*/
  1487.     curr = lll_find(CURRENT_FILE->first_line,true_line);
  1488.     if ((curr->name=(CHARTYPE *)(*the_malloc)(strlen(name)+1)) == NULL)
  1489.       {
  1490.        display_error(30,(CHARTYPE *)"",FALSE);
  1491. #ifdef TRACE
  1492.        trace_return();
  1493. #endif
  1494.        return(RC_OUT_OF_MEMORY);
  1495.       }
  1496.     strcpy(curr->name,name);
  1497.    }
  1498.  else
  1499.    {
  1500. /*---------------------------------------------------------------------*/
  1501. /* Find a line that already has the same name. If one exists, remove   */
  1502. /* the name otherwise display an error.                                */
  1503. /*---------------------------------------------------------------------*/
  1504.     if ((curr = find_named_line(name,&dummy,FALSE)) != (LINE *)NULL)
  1505.       {
  1506.        (*the_free)(curr->name);
  1507.        curr->name = (CHARTYPE *)NULL;
  1508.       }
  1509.     else
  1510.       {
  1511.        display_error(60,name,FALSE);
  1512. #ifdef TRACE
  1513.        trace_return();
  1514. #endif
  1515.        return(RC_INVALID_OPERAND);
  1516.       }
  1517.    }
  1518.  
  1519. #ifdef TRACE
  1520.  trace_return();
  1521. #endif
  1522.  return(RC_OK);
  1523. }
  1524. /***********************************************************************/
  1525. #ifdef PROTO
  1526. short execute_wrap_word(unsigned short col)
  1527. #else
  1528. short execute_wrap_word(col)
  1529. unsigned short col;
  1530. #endif
  1531. /***********************************************************************/
  1532. /* Parameters: col   - current column position within rec              */
  1533. /***********************************************************************/
  1534. {
  1535. /*-------------------------- external data ----------------------------*/
  1536.  extern bool INSERTMODEx;
  1537.  extern unsigned short rec_len;
  1538.  extern CHARTYPE *rec;
  1539. /*--------------------------- local data ------------------------------*/
  1540.  register short i=0;
  1541.  short col_break=0,cursor_offset=0;
  1542.  LINE *curr=NULL,*next_line=NULL;
  1543.  bool newline=FALSE,cursor_wrap=FALSE;
  1544.  CHARTYPE *buf=NULL,*word_to_wrap=NULL;
  1545.  short next_line_start=0,length_word=0,last_col=0;
  1546.  short rc=RC_OK;
  1547. /*--------------------------- processing ------------------------------*/
  1548. #ifdef TRACE
  1549.  trace_function("commutil.c:execute_wrap_word");
  1550. #endif
  1551. /*---------------------------------------------------------------------*/
  1552. /* This function is called when the length of the focus line exceeds   */
  1553. /* the right margin. If the cursor is positioned in the last word of   */
  1554. /* the line, the cursor moves with that word to the next line.         */
  1555. /* If the combined length of the word to be wrapped and a space and the*/
  1556. /* line following the focus line exceeds the right margin, a new line  */
  1557. /* is inserted with the word being wrapped, otherwise the word to be   */
  1558. /* wrapped is prepended to the following line.                         */
  1559. /*---------------------------------------------------------------------*/
  1560. /*---------------------------------------------------------------------*/
  1561. /* Find the current LINE pointer for the focus_line.                   */
  1562. /*---------------------------------------------------------------------*/
  1563.  curr = lll_find(CURRENT_FILE->first_line,CURRENT_VIEW->focus_line);
  1564. /*---------------------------------------------------------------------*/
  1565. /* Determine where to start splitting the line in relation to end of   */
  1566. /* line...                                                             */
  1567. /*---------------------------------------------------------------------*/
  1568.  col_break = memreveq(rec,' ',rec_len);
  1569. /*---------------------------------------------------------------------*/
  1570. /* If there is no word break, don't attempt any wrap.                  */
  1571. /*---------------------------------------------------------------------*/
  1572.  if (col_break == (-1))
  1573.    {
  1574. #ifdef TRACE
  1575.     trace_return();
  1576. #endif
  1577.     return(RC_OK);
  1578.    }
  1579. /*---------------------------------------------------------------------*/
  1580. /* Actual column to break on is 1 character to right of last space.    */
  1581. /*---------------------------------------------------------------------*/
  1582.  col_break++;
  1583. /*---------------------------------------------------------------------*/
  1584. /* Make a null terminated string out of current line so we can grab the*/
  1585. /* word to be wrapped.                                                 */
  1586. /*---------------------------------------------------------------------*/
  1587.  rec[rec_len] = '\0';
  1588. /*---------------------------------------------------------------------*/
  1589. /* Point to word to wrap and determine its length.                     */
  1590. /*---------------------------------------------------------------------*/
  1591.  length_word = rec_len - col_break;
  1592.  word_to_wrap = (CHARTYPE *)rec+col_break;
  1593. /*---------------------------------------------------------------------*/
  1594. /* If the position of the cursor is before the word to wrap leave the  */
  1595. /* cursor where it is.                                                 */
  1596. /*---------------------------------------------------------------------*/
  1597.  if (col >= col_break)
  1598.    {
  1599.     cursor_wrap = TRUE;
  1600.     cursor_offset = col - col_break - 1;
  1601.    }
  1602.  else
  1603.     cursor_wrap = FALSE;
  1604. /*---------------------------------------------------------------------*/
  1605. /* Now we have to work out if a new line is to added or we prepend to  */
  1606. /* the following line...                                               */
  1607. /*---------------------------------------------------------------------*/
  1608.  if (curr->next->next == NULL)             /* next line bottom of file */
  1609.     newline = TRUE;
  1610.  else
  1611.    {
  1612.     next_line = curr->next;
  1613.     if (!in_scope(next_line))
  1614.        newline = TRUE;
  1615.     else
  1616.       {
  1617.        next_line_start = memne(next_line->line,' ',next_line->length);
  1618.        if (next_line_start != CURRENT_VIEW->margin_left-1) /* next line doesn't start in left margin */
  1619.           newline = TRUE;
  1620.        else
  1621.          {
  1622.           if (next_line->length + length_word + 1 > CURRENT_VIEW->margin_right)
  1623.              newline = TRUE;
  1624.          }
  1625.       }
  1626.    }
  1627. /*---------------------------------------------------------------------*/
  1628. /* Save the word to be wrapped...                                      */
  1629. /*---------------------------------------------------------------------*/
  1630.  buf = (CHARTYPE *)(*the_malloc)(length_word+CURRENT_VIEW->margin_left);
  1631.  if (buf == NULL)
  1632.    {
  1633.     display_error(30,"",FALSE);
  1634. #ifdef TRACE
  1635.     trace_return();
  1636. #endif
  1637.     return(RC_OUT_OF_MEMORY);
  1638.    }
  1639.  memcpy(buf,word_to_wrap,length_word);
  1640. /*---------------------------------------------------------------------*/
  1641. /* Remove the word to be wrapped from the focus line buffer; rec...    */
  1642. /*---------------------------------------------------------------------*/
  1643.  for (i=col_break;i<rec_len+1;i++)
  1644.     rec[i] = ' ';
  1645.  last_col = memrevne(rec,' ',max_line_length);
  1646.  rec_len = (last_col == (-1)) ? 0 : last_col + 1;
  1647. /*---------------------------------------------------------------------*/
  1648. /* We now should know if a new line is to added or not.                */
  1649. /*---------------------------------------------------------------------*/
  1650.  if (newline)
  1651.    {
  1652.     for (i=0;i<CURRENT_VIEW->margin_left-1;i++)
  1653.        (void)meminschr(buf,' ',0,MAX_LENGTH_OF_LINE,i+length_word);
  1654.     curr = add_line(CURRENT_FILE->first_line,curr,buf,length_word+CURRENT_VIEW->margin_left-1,curr->select);
  1655.     CURRENT_FILE->number_lines++;
  1656.    }
  1657.  else
  1658.    {
  1659.     post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line);
  1660.     pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line+1L);
  1661.     (void)meminschr(rec,' ',CURRENT_VIEW->margin_left-1,MAX_LENGTH_OF_LINE,rec_len++);
  1662.     (void)meminsmem(rec,buf,length_word,CURRENT_VIEW->margin_left-1,
  1663.                     MAX_LENGTH_OF_LINE,rec_len);
  1664.     rec_len += length_word;
  1665.     post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line+1L);
  1666.     pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line);
  1667.    }
  1668.  (*the_free)(buf);
  1669. /*---------------------------------------------------------------------*/
  1670. /* We now should know if the cursor is to wrap or stay where it is.    */
  1671. /*---------------------------------------------------------------------*/
  1672.  if (cursor_wrap)
  1673.    {
  1674.     post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line);
  1675.     build_current_screen();
  1676.     cursor_down(TRUE);
  1677.     rc = Sos_firstchar("");
  1678.     for (i=0;i<cursor_offset+1;i++)
  1679.        rc = cursor_right(TRUE,FALSE);
  1680.    }
  1681.  else
  1682.    {
  1683.     if (INSERTMODEx)
  1684.        rc = cursor_right(TRUE,FALSE);
  1685.    }
  1686.  build_current_screen();
  1687.  display_current_screen();
  1688.  
  1689. #ifdef TRACE
  1690.  trace_return();
  1691. #endif
  1692.  return(rc);
  1693. }
  1694. /***********************************************************************/
  1695. #ifdef PROTO
  1696. short execute_split_join(bool action,bool aligned,short col)
  1697. #else
  1698. short execute_split_join(action,aligned,col)
  1699. bool action,aligned;
  1700. short col;
  1701. #endif
  1702. /***********************************************************************/
  1703. /* Parameters: action  - split or join line                            */
  1704. /*             aligned - whether to align text or not                  */
  1705. /*             col     - column to split on                            */
  1706. /***********************************************************************/
  1707. {
  1708. /*-------------------------- external data ----------------------------*/
  1709.  extern unsigned short rec_len;
  1710.  extern CHARTYPE *rec;
  1711. /*--------------------------- local data ------------------------------*/
  1712.  register short i=0;
  1713.  short num_cols=0,num_blanks_focus=0,num_blanks_next=0;
  1714.  unsigned short x=0,y=0;
  1715.  LINE *curr=NULL;
  1716.  LINETYPE true_line=CURRENT_VIEW->focus_line;
  1717. /*--------------------------- processing ------------------------------*/
  1718. #ifdef TRACE
  1719.  trace_function("execute.c: execute_split_join");
  1720. #endif
  1721.  if (CURRENT_VIEW->current_window != WINDOW_MAIN)
  1722.    {
  1723.     display_error(38,(CHARTYPE *)"",FALSE);
  1724. #ifdef TRACE
  1725.     trace_return();
  1726. #endif
  1727.     return(RC_INVALID_ENVIRON);
  1728.    }
  1729. /*---------------------------------------------------------------------*/
  1730. /* Reject the command if on the top or bottom line.                    */
  1731. /*---------------------------------------------------------------------*/
  1732.  if (FOCUS_TOF || FOCUS_BOF)
  1733.    {
  1734.     display_error(38,(CHARTYPE *)"",FALSE);
  1735. #ifdef TRACE
  1736.     trace_return();
  1737. #endif
  1738.     return(RC_INVALID_ENVIRON);
  1739.    }
  1740. /*---------------------------------------------------------------------*/
  1741. /* Copy any changes in the focus line to the linked list.              */
  1742. /*---------------------------------------------------------------------*/
  1743.  post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line);
  1744. /*---------------------------------------------------------------------*/
  1745. /* Find the current LINE pointer for the focus_line.                   */
  1746. /*---------------------------------------------------------------------*/
  1747.  curr = lll_find(CURRENT_FILE->first_line,true_line);
  1748.  
  1749.  getyx(CURRENT_WINDOW,y,x);
  1750.  switch(action)
  1751.    {
  1752.     case TRUE:
  1753.          memset(rec,' ',max_line_length);
  1754.          memcpy(rec,curr->line+col,curr->length);
  1755.          rec_len = curr->length-col;
  1756. /*---------------------------------------------------------------------*/
  1757. /* Calculate the number of leading blanks on the current line so that  */
  1758. /* the new line can have this many blanks prepended to align properly. */
  1759. /*---------------------------------------------------------------------*/
  1760.          if (aligned)
  1761.            {
  1762.             num_cols = memne(curr->line,' ',curr->length);
  1763.             if (num_cols == (-1))
  1764.                num_cols = 0;
  1765.             for (i=0;i<num_cols;i++)
  1766.                meminschr(rec,' ',0,max_line_length,rec_len++);
  1767.             rec_len = min(rec_len,max_line_length);
  1768.            }
  1769.          add_line(CURRENT_FILE->first_line,curr,(rec),rec_len,curr->select);
  1770.          CURRENT_FILE->number_lines++;
  1771.          pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line);
  1772.          Sos_delend("");
  1773.          post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line);
  1774.          break;
  1775.     case FALSE:
  1776.          if (curr->next->next == NULL)
  1777.            {
  1778. /*---------------------------------------------------------------------*/
  1779. /* Trying to join with the bottom of file line.                        */
  1780. /*---------------------------------------------------------------------*/
  1781. #ifdef TRACE
  1782.            trace_return();
  1783. #endif
  1784.            return(RC_INVALID_ENVIRON);
  1785.           }
  1786. /*---------------------------------------------------------------------*/
  1787. /* Calculate the number of leading blanks for the focus line and also  */
  1788. /* for the line to be joined. To align the join properly, we have to   */
  1789. /* remove up the number of leading blanks in the focus line from the   */
  1790. /* beginning of the line to be joined.                                 */
  1791. /*---------------------------------------------------------------------*/
  1792.          if (aligned)
  1793.            {
  1794.             num_blanks_focus = memne(curr->line,' ',curr->length);
  1795.             if (num_blanks_focus == (-1))
  1796.                num_blanks_focus = 0;
  1797.             num_blanks_next = memne(curr->next->line,' ',curr->length);
  1798.             if (num_blanks_next == (-1))
  1799.                num_blanks_next = 0;
  1800.             num_cols = min(num_blanks_focus,num_blanks_next);
  1801.            }
  1802.          else
  1803.             num_cols = 0;
  1804.          meminsmem(rec,curr->next->line+num_cols,curr->next->length-num_cols,
  1805.                       col,max_line_length,col);
  1806.          rec_len = min(max_line_length,col+curr->next->length-num_cols);
  1807.          post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line);
  1808.          curr = delete_line(CURRENT_FILE->first_line,curr->next,DIRECTION_BACKWARD);
  1809. /*---------------------------------------------------------------------*/
  1810. /* If on the bottom line, use the previous line.                       */
  1811. /*---------------------------------------------------------------------*/
  1812.          if (CURRENT_BOF)
  1813.            {
  1814.             CURRENT_VIEW->current_line--;
  1815.             y++;
  1816.            }
  1817. /*---------------------------------------------------------------------*/
  1818. /* Decrement the number of lines counter for the current file and move */
  1819. /* the cursor to the appropriate line.                                 */
  1820. /*---------------------------------------------------------------------*/
  1821.          CURRENT_FILE->number_lines--;
  1822.          wmove(CURRENT_WINDOW,y,x);
  1823.          break;
  1824.    }
  1825. /*---------------------------------------------------------------------*/
  1826. /* Fix the positioning of the marked block (if there is one and it is  */
  1827. /* in the current view) and any pending prefix commands.               */
  1828. /*---------------------------------------------------------------------*/
  1829.  adjust_marked_lines(action,true_line,1L);
  1830.  adjust_pending_prefix(CURRENT_VIEW,action,true_line,1L);
  1831.  build_current_screen();
  1832.  display_current_screen();
  1833. #ifdef TRACE
  1834.  trace_return();
  1835. #endif
  1836.  return(RC_OK);
  1837. }
  1838. /***********************************************************************/
  1839. #ifdef PROTO
  1840. short execute_put(CHARTYPE *params,bool putdel)
  1841. #else
  1842. short execute_put(params,putdel)
  1843. CHARTYPE *params;
  1844. bool putdel;
  1845. #endif
  1846. /***********************************************************************/
  1847. {
  1848. /*-------------------------- external data ----------------------------*/
  1849.  extern CHARTYPE *tempfilename;
  1850.  extern CHARTYPE sp_path[MAX_FILE_NAME+1] ;
  1851.  extern CHARTYPE sp_fname[MAX_FILE_NAME+1] ;
  1852.  extern VIEW_DETAILS *vd_mark;
  1853.  extern CHARTYPE *temp_cmd;
  1854. /*--------------------------- local data ------------------------------*/
  1855.  LINETYPE num_lines=0L,true_line=0L;
  1856.  bool append=FALSE;
  1857.  CHARTYPE *filename=NULL;
  1858.  short rc=RC_OK,start_col=0,end_col=max_line_length;
  1859.  TARGET target;
  1860.  short target_type=TARGET_NORMAL|TARGET_BLOCK_CURRENT|TARGET_ALL|TARGET_SPARE;
  1861. /*--------------------------- processing ------------------------------*/
  1862. #ifdef TRACE
  1863.  trace_function("execute.c: execute_put");
  1864. #endif
  1865. /*---------------------------------------------------------------------*/
  1866. /* If there are no arguments, default to "1"...                        */
  1867. /*---------------------------------------------------------------------*/
  1868.  if (strcmp("",params) == 0)
  1869.     params = (CHARTYPE *)"1";
  1870. /*---------------------------------------------------------------------*/
  1871. /* Validate first argument as a target...                              */
  1872. /*---------------------------------------------------------------------*/
  1873.  initialise_target(&target);
  1874.  if ((rc = validate_target(params,&target,target_type,get_true_line(),TRUE,TRUE)) != RC_OK)
  1875.    {
  1876.     free_target(&target);
  1877. #ifdef TRACE
  1878.     trace_return();
  1879. #endif
  1880.     return(rc);
  1881.    }
  1882. /*---------------------------------------------------------------------*/
  1883. /* If there is no second argument, no filename supplied...             */
  1884. /*---------------------------------------------------------------------*/
  1885.  if (target.spare == (-1))
  1886.    {
  1887.     append = FALSE;
  1888.     filename = tempfilename;
  1889.    }
  1890.  else
  1891.    {
  1892.     if ((rc = splitpath(strtrunc(target.rt[target.spare].string))) != RC_OK)
  1893.       {
  1894.        display_error(10,strtrunc(target.rt[target.spare].string),FALSE);
  1895.        free_target(&target);
  1896. #ifdef TRACE
  1897.        trace_return();
  1898. #endif
  1899.        return(rc);
  1900.       }
  1901.     strcpy(temp_cmd,sp_path);
  1902.     strcat(temp_cmd,sp_fname);
  1903.     filename = temp_cmd;
  1904.     append = TRUE;
  1905.    }
  1906.  true_line = target.true_line;
  1907.  num_lines = target.num_lines;
  1908. /*---------------------------------------------------------------------*/
  1909. /* If the marked block is a BOX block, set up the left and right column*/
  1910. /* values.                                                             */
  1911. /*---------------------------------------------------------------------*/
  1912.  if (target.rt[0].target_type == TARGET_BLOCK_CURRENT
  1913.  && MARK_VIEW->mark_type == M_BOX)
  1914.    {
  1915.     start_col = MARK_VIEW->mark_start_col-1;
  1916.     end_col = MARK_VIEW->mark_end_col-1;
  1917.    }
  1918.  post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line);
  1919.  if ((rc = save_file(CURRENT_FILE,filename,TRUE,num_lines,true_line,append,start_col,end_col,FALSE)) != RC_OK)
  1920.    {
  1921.     free_target(&target);
  1922. #ifdef TRACE
  1923.     trace_return();
  1924. #endif
  1925.     return(rc);
  1926.    }
  1927. /*---------------------------------------------------------------------*/
  1928. /* If we are executing a putd command, delete the target...            */
  1929. /*---------------------------------------------------------------------*/
  1930.  if (putdel)
  1931.     rc = DeleteLine(target.string);
  1932.  free_target(&target);
  1933. #ifdef TRACE
  1934.  trace_return();
  1935. #endif
  1936.  return(rc);
  1937. }
  1938. /***********************************************************************/
  1939. #ifdef PROTO
  1940. short execute_macro(CHARTYPE *params,bool error_on_not_found)
  1941. #else
  1942. short execute_macro(params,error_on_not_found)
  1943. CHARTYPE *params;
  1944. bool error_on_not_found;
  1945. #endif
  1946. /***********************************************************************/
  1947. {
  1948. /*-------------------------- external data ----------------------------*/
  1949.  extern bool in_macro;
  1950.  extern bool rexx_support;
  1951.  extern CHARTYPE number_of_files;
  1952.  extern LINETYPE original_screen_line;
  1953.  extern LINETYPE original_screen_column;
  1954.  extern LINETYPE original_file_line;
  1955.  extern LINETYPE original_file_column;
  1956. /*--------------------------- local data ------------------------------*/
  1957.  short rc=RC_OK;
  1958.  short errnum=0;
  1959.  FILE *fp=NULL;
  1960. #define MAC_PARAMS  2
  1961.  CHARTYPE *word[MAC_PARAMS+1];
  1962.  unsigned short num_params=0;
  1963.  CHARTYPE *macroname=NULL;
  1964. /*--------------------------- processing ------------------------------*/
  1965. #ifdef TRACE
  1966.  trace_function("execute.c: execute_macro");
  1967. #endif
  1968. /*---------------------------------------------------------------------*/
  1969. /* Validate the parameters. At least 1 must be present, the filename.  */
  1970. /*---------------------------------------------------------------------*/
  1971.  num_params = param_split(params,word,MAC_PARAMS,WORD_DELIMS,TEMP_PARAM);
  1972.  if (num_params == 0)
  1973.    {
  1974.     display_error(3,(CHARTYPE *)"",FALSE);
  1975. #ifdef TRACE
  1976.     trace_return();
  1977. #endif
  1978.     return(RC_INVALID_OPERAND);
  1979.    }
  1980. /*---------------------------------------------------------------------*/
  1981. /* Allocate some space for macroname...                                */
  1982. /*---------------------------------------------------------------------*/
  1983.  if ((macroname = (CHARTYPE *)(*the_malloc)((MAX_FILE_NAME+1)*sizeof(CHARTYPE))) == NULL)
  1984.    {
  1985.     display_error(30,(CHARTYPE *)"",FALSE);
  1986. #ifdef TRACE
  1987.     trace_return();
  1988. #endif
  1989.     return(RC_OUT_OF_MEMORY);
  1990.    }
  1991. /*---------------------------------------------------------------------*/
  1992. /* Find the fully qualified file name for the supplied macro name.     */
  1993. /*---------------------------------------------------------------------*/
  1994.  rc = get_valid_macro_file_name(word[0],macroname,&errnum);
  1995. /*---------------------------------------------------------------------*/
  1996. /* Validate the return code...                                         */
  1997. /*---------------------------------------------------------------------*/
  1998.  switch(rc)
  1999.    {
  2000. /*---------------------------------------------------------------------*/
  2001. /* If RC_OK, continue to process the macro...                          */
  2002. /*---------------------------------------------------------------------*/
  2003.     case RC_OK:
  2004.          break;
  2005. /*---------------------------------------------------------------------*/
  2006. /* If RC_FILE_NOT_FOUND and IMPOS is not on, display an error and exit.*/
  2007. /* If IMPOS is on, just return without displaying an error.            */
  2008. /*---------------------------------------------------------------------*/
  2009.     case RC_FILE_NOT_FOUND:
  2010.          if (error_on_not_found)
  2011.             display_error(errnum,macroname,FALSE);
  2012.          (*the_free)(macroname);
  2013. #ifdef TRACE
  2014.          trace_return();
  2015. #endif
  2016.          return(rc);
  2017.          break;
  2018. /*---------------------------------------------------------------------*/
  2019. /* All other cases, display error and return.                          */
  2020. /*---------------------------------------------------------------------*/
  2021.     default:
  2022.          (*the_free)(macroname);
  2023.          display_error(errnum,macroname,FALSE);
  2024. #ifdef TRACE
  2025.          trace_return();
  2026. #endif
  2027.          return(rc);
  2028.    }
  2029. /*---------------------------------------------------------------------*/
  2030. /* Set in_macro = TRUE to stop multiple show_page()s being performed.  */
  2031. /*---------------------------------------------------------------------*/
  2032.  in_macro = TRUE;
  2033. /*---------------------------------------------------------------------*/
  2034. /* Save the values of the cursor position...                           */
  2035. /*---------------------------------------------------------------------*/
  2036.  get_cursor_position(&original_screen_line,&original_screen_column,
  2037.                      &original_file_line,&original_file_column);
  2038. /*---------------------------------------------------------------------*/
  2039. /* If REXX is supported, process the macro as a REXX macro...          */
  2040. /*---------------------------------------------------------------------*/
  2041.  if (rexx_support)
  2042.    {
  2043.     post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line);
  2044.     rc = execute_macro_file(macroname,word[1]);
  2045.     if (rc != RC_OK)
  2046.       {
  2047.        display_error(54,(CHARTYPE *)"",FALSE);
  2048.        rc = RC_SYSTEM_ERROR;
  2049.       }
  2050.    }
  2051.  else
  2052.    {
  2053. /*---------------------------------------------------------------------*/
  2054. /* ...otherwise, process the file as a non-REXX macro file...          */
  2055. /*---------------------------------------------------------------------*/
  2056.     if ((fp = fopen(macroname,"r")) == NULL)
  2057.       {
  2058.        rc = RC_ACCESS_DENIED;
  2059.        display_error(8,macroname,FALSE);
  2060.       }
  2061.     post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line);
  2062.     if (rc == RC_OK)
  2063.       {
  2064.        rc = execute_command_file(fp);
  2065.        fclose(fp);
  2066.       }
  2067.     (*the_free)(macroname);
  2068.     if (rc == RC_SYSTEM_ERROR)
  2069.        display_error(53,"",FALSE);
  2070.    }
  2071. /*---------------------------------------------------------------------*/
  2072. /* Set in_macro = FALSE to indicate we are out of the macro and do a   */
  2073. /* show_page() now as long as there are still file(s) in the ring.     */
  2074. /*---------------------------------------------------------------------*/
  2075.  in_macro = FALSE;
  2076.  if (number_of_files > 0)
  2077.    {
  2078.     build_current_screen();
  2079.     display_current_screen();
  2080.    }
  2081.  
  2082. #ifdef TRACE
  2083.  trace_return();
  2084. #endif
  2085.  return(rc);
  2086. }
  2087. /***********************************************************************/
  2088. #ifdef PROTO
  2089. short execute_set_on_off(CHARTYPE *params,bool *flag)
  2090. #else
  2091. short execute_set_on_off(params,flag)
  2092. CHARTYPE *params;
  2093. bool *flag;
  2094. #endif
  2095. /***********************************************************************/
  2096. {
  2097. /*-------------------------- external data ----------------------------*/
  2098. /*--------------------------- local data ------------------------------*/
  2099.  short rc=RC_OK;
  2100. /*--------------------------- processing ------------------------------*/
  2101. #ifdef TRACE
  2102.  trace_function("execute.c: execute_set_on_off");
  2103. #endif
  2104. /*---------------------------------------------------------------------*/
  2105. /* Validate the parameter. It must be ON or OFF.                       */
  2106. /*---------------------------------------------------------------------*/
  2107.  if (equal((CHARTYPE *)"off",params,3))
  2108.     *flag = FALSE;
  2109.  else
  2110.     if (equal((CHARTYPE *)"on",params,2))
  2111.        *flag = TRUE;
  2112.     else
  2113.       {
  2114.        display_error(1,(CHARTYPE *)params,FALSE);
  2115. #ifdef TRACE
  2116.        trace_return();
  2117. #endif
  2118.        rc = RC_INVALID_OPERAND;
  2119.       }
  2120. #ifdef TRACE
  2121.  trace_return();
  2122. #endif
  2123.  return(rc);
  2124. }
  2125. /***********************************************************************/
  2126. #ifdef PROTO
  2127. short execute_set_row_position(CHARTYPE *params,short *base,short *off)
  2128. #else
  2129. short execute_set_row_position(params,base,off)
  2130. CHARTYPE *params;
  2131. short *base,*off;
  2132. #endif
  2133. /***********************************************************************/
  2134. {
  2135. /*-------------------------- external data ----------------------------*/
  2136. /*--------------------------- local data ------------------------------*/
  2137.  short rc=RC_OK;
  2138. /*--------------------------- processing ------------------------------*/
  2139. #ifdef TRACE
  2140.  trace_function("execute.c: execute_set_row_position");
  2141. #endif
  2142.  if (*params == 'M'
  2143.  ||  *params == 'm')
  2144.    {
  2145.     *base = POSITION_MIDDLE;
  2146.     params++;
  2147.     if (blank_field(params))
  2148.        *off = 0;
  2149.     else
  2150.       {
  2151.        if ((*params != '-'
  2152.        &&  *params != '+')
  2153.        || ((*off = atoi(params)) == 0))
  2154.          {
  2155.           display_error(1,params,FALSE);
  2156. #ifdef TRACE
  2157.           trace_return();
  2158. #endif
  2159.           return(RC_INVALID_OPERAND);
  2160.          }
  2161.       }
  2162.    }
  2163.  else
  2164.    {
  2165.     if ((*off = atoi(params)) == 0)
  2166.       {
  2167.        display_error(1,params,FALSE);
  2168. #ifdef TRACE
  2169.        trace_return();
  2170. #endif
  2171.        return(RC_INVALID_OPERAND);
  2172.       }
  2173.     *base = (*off > 0) ? POSITION_TOP : POSITION_BOTTOM;
  2174.    }
  2175. #ifdef TRACE
  2176.  trace_return();
  2177. #endif
  2178.  return(rc);
  2179. }
  2180. /***********************************************************************/
  2181. #ifdef PROTO
  2182. short processable_line(VIEW_DETAILS *view,LINETYPE true_line,LINE *curr)
  2183. #else
  2184. short processable_line(view,true_line,curr)
  2185. VIEW_DETAILS *view;
  2186. LINETYPE true_line;
  2187. LINE *curr;
  2188. #endif
  2189. /***********************************************************************/
  2190. {
  2191. /*-------------------------- external data ----------------------------*/
  2192. /*--------------------------- local data ------------------------------*/
  2193. /*--------------------------- processing ------------------------------*/
  2194. #ifdef TRACE
  2195.  trace_function("execute.c: processable_line");
  2196. #endif
  2197.  if (VIEW_TOF(view,true_line)
  2198.  ||  VIEW_BOF(view,true_line))
  2199.    {
  2200. #ifdef TRACE
  2201.     trace_return();
  2202. #endif
  2203.     return(LINE_TOF_EOF);
  2204.    }
  2205.  if (in_scope(curr))
  2206.    {
  2207. #ifdef TRACE
  2208.     trace_return();
  2209. #endif
  2210.     return(LINE_LINE);
  2211.    }
  2212. #ifdef TRACE
  2213.  trace_return();
  2214. #endif
  2215.  return(LINE_SHADOW);
  2216. }
  2217. /***********************************************************************/
  2218. #ifdef PROTO
  2219. short execute_expand(CHARTYPE *params,bool inc_alt,bool use_tabs,bool add_to_recovery)
  2220. #else
  2221. short execute_expand(params,inc_alt,use_tabs,add_to_recovery)
  2222. CHARTYPE *params;
  2223. bool inc_alt,use_tabs,add_to_recovery;
  2224. #endif
  2225. /***********************************************************************/
  2226. {
  2227. /*-------------------------- external data ----------------------------*/
  2228.  extern bool curses_started;
  2229. /*--------------------------- local data ------------------------------*/
  2230.  LINETYPE i=0L,num_actual_lines=0L;
  2231.  LINETYPE num_lines=0L,true_line=0L;
  2232.  unsigned short x=0,y=0;
  2233.  short direction=0,rc=RC_OK;
  2234.  LINE *curr=NULL;
  2235.  TARGET target;
  2236.  short target_type=TARGET_NORMAL|TARGET_BLOCK_CURRENT|TARGET_ALL;
  2237.  bool lines_based_on_scope=FALSE;
  2238. /*---------------------------------------------------------------------*/
  2239. /* Validate the parameters that have been supplied.                    */
  2240. /* If no parameter is supplied, 1 is assumed.                          */
  2241. /*---------------------------------------------------------------------*/
  2242.  true_line = get_true_line();
  2243.  if (strcmp("",params) == 0)
  2244.     params = (CHARTYPE *)"1";
  2245.  initialise_target(&target);
  2246.  if ((rc = validate_target(params,&target,target_type,true_line,TRUE,TRUE)) != RC_OK)
  2247.    {
  2248.     free_target(&target);
  2249. #ifdef TRACE
  2250.     trace_return();
  2251. #endif
  2252.     return(rc);
  2253.    }
  2254.  post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line);
  2255. /*---------------------------------------------------------------------*/
  2256. /* Determine in which direction we are working.                        */
  2257. /*---------------------------------------------------------------------*/
  2258.  if (target.num_lines < 0L)
  2259.    {
  2260.     direction = DIRECTION_BACKWARD;
  2261.     num_lines = -target.num_lines;
  2262.    }
  2263.  else
  2264.    {
  2265.     direction = DIRECTION_FORWARD;
  2266.     num_lines = target.num_lines;
  2267.    }
  2268.  true_line = target.true_line;
  2269.  lines_based_on_scope = (target.rt[0].target_type == TARGET_BLOCK_CURRENT) ? FALSE : TRUE;
  2270. /*---------------------------------------------------------------------*/
  2271. /* Find the current LINE pointer for the true_line.                    */
  2272. /* This is the first line to change.                                   */
  2273. /*---------------------------------------------------------------------*/
  2274.  curr = lll_find(CURRENT_FILE->first_line,true_line);
  2275. /*---------------------------------------------------------------------*/
  2276. /* Convert all tabs in the current line to spaces.                     */
  2277. /*---------------------------------------------------------------------*/
  2278.  for (i=0L,num_actual_lines=0L;;i++)
  2279.    {
  2280.     if (lines_based_on_scope)
  2281.       {
  2282.        if (num_actual_lines == num_lines)
  2283.           break;
  2284.       }
  2285.     else
  2286.       {
  2287.        if (num_lines == i)
  2288.           break;
  2289.       }
  2290.     rc = processable_line(CURRENT_VIEW,true_line+(LINETYPE)(i*direction),curr);
  2291.     switch(rc)
  2292.       {
  2293.        case LINE_SHADOW:
  2294.             break;
  2295.        case LINE_TOF_EOF:
  2296.             num_actual_lines++;
  2297.             break;
  2298.        default:
  2299.             tabs_convert(curr,TRUE,inc_alt,use_tabs,add_to_recovery);
  2300.             num_actual_lines++;
  2301.       }
  2302.     if (direction == DIRECTION_FORWARD)
  2303.        curr = curr->next;
  2304.     else
  2305.        curr = curr->prev;
  2306.    }
  2307. /*---------------------------------------------------------------------*/
  2308. /* If STAY is OFF, change the current and focus lines by the number    */
  2309. /* of lines calculated from the target.                                */
  2310. /*---------------------------------------------------------------------*/
  2311.  if (!CURRENT_VIEW->stay                                 /* stay is off */
  2312.  &&  target.num_lines != 0L)
  2313.     CURRENT_VIEW->focus_line = CURRENT_VIEW->current_line = target.true_line+target.num_lines-(LINETYPE)direction;
  2314.  free_target(&target);
  2315.  pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line);
  2316.  build_current_screen(); 
  2317.  display_current_screen();
  2318.  if (CURRENT_VIEW->current_window != WINDOW_COMMAND
  2319.  &&  curses_started)
  2320.    {
  2321.     getyx(CURRENT_WINDOW,y,x);
  2322.     y = get_row_for_focus_line(CURRENT_VIEW->focus_line,
  2323.                                CURRENT_VIEW->current_row);
  2324.     wmove(CURRENT_WINDOW,y,x);
  2325.    }
  2326. #ifdef TRACE
  2327.  trace_return();
  2328. #endif
  2329.  if (CURRENT_TOF || CURRENT_BOF)
  2330.     return(RC_TOF_EOF_REACHED);
  2331.  else
  2332.     return(RC_OK);
  2333. }
  2334. /***********************************************************************/
  2335. #ifdef PROTO
  2336. short execute_move_cursor(LENGTHTYPE col)
  2337. #else
  2338. short execute_move_cursor(col)
  2339. LENGTHTYPE col;
  2340. #endif
  2341. /***********************************************************************/
  2342. {
  2343. /*-------------------------- external data ----------------------------*/
  2344. /*--------------------------- local data ------------------------------*/
  2345.  short y=0,x=0,rc=RC_OK;
  2346.  COLTYPE new_screen_col=0;
  2347.  LENGTHTYPE new_verify_col=0;
  2348. /*--------------------------- processing ------------------------------*/
  2349. #ifdef TRACE
  2350.  trace_function("execute.c: execute_move_cursor");
  2351. #endif
  2352. /*---------------------------------------------------------------------*/
  2353. /* Don't do anything for PREFIX window...                              */
  2354. /*---------------------------------------------------------------------*/
  2355.  if (CURRENT_VIEW->current_window == WINDOW_PREFIX)
  2356.    {
  2357. #ifdef TRACE
  2358.     trace_return();
  2359. #endif
  2360.     return(RC_OK);
  2361.    }
  2362.  
  2363.  getyx(CURRENT_WINDOW,y,x);
  2364.  calculate_new_column(x,CURRENT_VIEW->verify_col,col,&new_screen_col,&new_verify_col);
  2365.  if (CURRENT_VIEW->verify_col != new_verify_col
  2366.  &&  CURRENT_VIEW->current_window == WINDOW_MAIN)
  2367.    {
  2368.     CURRENT_VIEW->verify_col = new_verify_col;
  2369.     build_current_screen(); 
  2370.     display_current_screen();
  2371.    }
  2372.  wmove(CURRENT_WINDOW,y,new_screen_col);
  2373.  
  2374. #ifdef TRACE
  2375.  trace_return();
  2376. #endif
  2377.  return(RC_OK);
  2378. }
  2379.